# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: waterbear <st92.at.freeshell.org>

pkgname=simh
pkgver=3.12.3
_pkgver=${pkgver//./-}
_pkgver=${_pkgver/-/.}
pkgrel=2
pkgdesc="simulator for assorted historical computers, from Altair to VAX"
arch=('loong64' 'x86_64')
url="http://simh.trailing-edge.com"
license=("BSD")
depends=("libpcap")
makedepends=("unzip" "linux-api-headers")
install=simh.install
source=("$pkgname-$pkgver.tar.gz::https://github.com/open-simh/simh/archive/v${_pkgver}.tar.gz"
	"LICENSE"
	build-fix.patch)
sha512sums=('ee473f30efcf2f63a6bd943d268adb32fa047ee30d97a250621a06db890ba6e96956268555e3f49e9dc758fa25c5c4f4070f2b05db0ab6625c072c7875b207cc'
            '084faf8a66c95cb337bca19a6116c916aa04fc23ec5d57d5d8c2fc168231272123a705e83f8da2bf38f404da51727a69db68ffd87b36028e0cde52b54b92b2dd'
            '663a5514333653352ad6134e42eca2a8c780f4d7c140dcc30063893c7470bdafe704703eee23ea89272d04acff2cdae013781b0345c2d9e9d86fcb42c50db530')

prepare() {
  cd "$srcdir/$pkgname-${_pkgver}"
  patch -p1 <../build-fix.patch
  sed -i '/Retry your build without specifying USE_NETWORK/d' makefile
}

build() {
  cd "$srcdir/$pkgname-${_pkgver}"
  mkdir -p BIN
  make USE_SHARED=1 USE_NETWORK=1 NETWORK_OPT='-DUSE_NETWORK -DHAVE_TAP_NETWORK'
}

package() {
  cd "$srcdir/$pkgname-${_pkgver}/BIN"
  rmdir buildtools || true
  for i in *; do
    install -D $i "$pkgdir/usr/bin/simh-$i"
  done

  cd "../VAX"
  mkdir -p "$pkgdir/usr/lib/simh"
  cp *.bin "$pkgdir/usr/lib/simh"

  install -Dm644 "$srcdir/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
